﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Training.Presentation;
using Training.Application;
using TrainingApplication;
using Training.Domain;
using Training.Application.Services;

namespace Training.Presentation
{
    class Program
    {
        public static IPersonAppService personAppService { get; set; }

        static void Main(string[] args)
        {
            personAppService = new PersonAppService();
            Screen.StartApplication();
        }

        public static void ListsMenu()
        {
            Console.Clear();
            var persons = new List<Person>();
            var selection = -1;
            switch (Menu.ListPersonsMenu())
            {
                case ListMenuEnum.AllPersons:
                    persons = personAppService.GetAll().ToList();
                    selection = Screen.ShowList(persons);

                    //TODO: Validate count of persons, validate if selection is 999 to exit
                    if (persons[selection] != null) 
                        EditPerson(persons[selection]);
                    else
                        Screen.StartApplication();
                    break;
                case ListMenuEnum.RebootApplication:
                    Screen.StartApplication();
                    break;
                case ListMenuEnum.Exit:
                default:
                    break;
            }
        }

        private static void EditPerson(Person person)
        {
            Console.Clear();
            Screen.ShowItem(person);
        }

        public static void SaveValue(Person person, int indexEnumFiled, string newValue)
        {
            person.RefreshValue(indexEnumFiled, newValue);
            personAppService.Save(person);
            Screen.StartApplication();
        }

        public static void SaveItem(Person person)
        {
            personAppService.Save(person);
            Screen.StartApplication();
        }

        public static void RemoveItem(string vat)
        {
            personAppService.RemoveItem(vat);
            Screen.StartApplication();
        }
    }
}
